Class PrioritySet<T>

Type Parameters:
T - the type of object to manage in the PriorityQueue.
All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, Queue<T>

public class PrioritySet<T> extends PriorityQueue<T>
Represents a PrioritySet. Operates as an extension of the java.util.PriorityQueue in that it does not allow duplicate elements. Furthermore, it may be configured so that on addition of similar elements (i.e. elements that are equivalent via .equals() but have different weight values) the higher of the two values is kept via comparator analysis. That is to say, if a Comparator indicates that a newly added object should come BEFORE the other object in a descending order, then the old object is replaced. This can be leveraged to perform a descending-based replacement if the comparator is configured properly. (i.e. a 4 replacing a 5.)
Version:
1.1 May 28, 2015
Author:
Charles Allen Schultz II
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • addOverride

      private final boolean addOverride
      Boolean indicating if newer elements with a greater compare value should replace others.
  • Constructor Details

    • PrioritySet

      public PrioritySet(boolean addOverride)
      Public constructor for initializing a PrioritySet. Utilizes the natural ordering of the elements.
      Parameters:
      addOverride - a boolean indicating if new elements may override older ones based on the comparator's value.
    • PrioritySet

      public PrioritySet(Comparator<T> compare, boolean addOverride)
      Public constructor for initializing a PrioritySet. Requires both a comparator for comparing elements and a boolean indicating if addOverride should be enabled.
      Parameters:
      compare - the Comparator to use for queue ordering.
      addOverride - a boolean indicating if new elements may override older ones based on the comparator's value.
  • Method Details

    • add

      public boolean add(T t)
      Allows additions of items that already has a copy within the set (determined by obj.equals(obj2) ) and their subsequent replacement if they are of lesser value than the new object as determined by the queue's comparator.

      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Queue<T>
      Overrides:
      add in class PriorityQueue<T>
      Parameters:
      t - the T type object to add.
      Returns:
      true if added, false if not.